package com.rjhch.hadoopTest;

import org.apache.hadoop.security.UserGroupInformation;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class TestPhoenixDriver {

    public static void main(String[] args) throws Exception {
        Statement stmt = null;
        ResultSet rs = null;
        UserGroupInformation.loginUserFromKeytab("hadoop/hadoop01@HADOOP.COM", "D:\\keytab\\hadoop.keytab");
        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

        Properties props = new Properties();
//        props.setProperty("TenantId", "wanger");
//        Connection conn = DriverManager.getConnection("jdbc:phoenix:hadoop01,hadoop02,hadoop03:2181", props);
        Connection conn = DriverManager.getConnection("jdbc:phoenix:hadoop01,hadoop02,hadoop03:2181");

        /* 在Phoenix中，如果table name/view name、column name等字符串不加上双引号就会被认为是大写。所以，这里的brand_name要加上双引号  */
        String sql;
        sql = "select * from DEPB_INFO_JI_NAN where DATA_DATE='20180831' limit 10";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();

        while (rs.next()) {
            int columnCount = rs.getMetaData().getColumnCount();
            List<String> data = new ArrayList<>();
            for (int i = 0; i < columnCount; i++) {
                data.add(rs.getString(i + 1));
            }
            System.err.println(data);
        }
        /* 关闭资源*/
        rs.close();
        pstmt.close();
    }
}
